package com.photoeditor.demo.ui.dialog;

import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.photoeditor.demo.statistics.StatisticsUtils;

import java.lang.ref.WeakReference;

import static com.photoeditor.demo.statistics.StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_RATE_GUIDE_VALUE_CLOSE;

public class BaseVirtualRateDialog extends BaseDialog {


    protected WeakReference<IDialog.IListener> mListener;

    protected WeakReference<RateGuide.OnRateChageListener> mOnRateChageListener;

    public BaseVirtualRateDialog(Context context) {
        super(context);

        mOnRateChageListener = RateGuide.getOnRateChageListener();
        mListener = RateGuide.getListener();
    }

    @Override
    public void dismiss() {
        if (mOnRateChageListener != null && mOnRateChageListener.get() != null) {
            mOnRateChageListener.get().onDisimiss();
        }
        super.dismiss();
    }

    @Override
    public void show() {
        Window window = getWindow();
        if (window != null) {
            View decorView = window.getDecorView();
            if (decorView != null) {
                decorView.setPadding(0, 0, 0, 0);
            }
            WindowManager.LayoutParams lp = window.getAttributes();
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;
            window.setAttributes(lp);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            } else {
                window.setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            }
        }
        super.show();
    }

    @Override
    public void onBackPressed() {
        if (mListener != null && mListener.get() instanceof IRateDialogListener) {
            ((IRateDialogListener) mListener.get()).onCloseClick();
        }
        super.onBackPressed();
    }
}
